<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\City;
use App\Models\District;

class DistrictSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // 获取主要城市
        $beijing = City::where('code', '110100')->first();
        $tianjin = City::where('code', '120100')->first();
        $haerbin = City::where('code', '230100')->first();
        $qiqihaer = City::where('code', '230200')->first();
        $daqing = City::where('code', '230600')->first();
        $shanghai = City::where('code', '310100')->first();
        $guangzhou = City::where('code', '440100')->first();
        $shenzhen = City::where('code', '440300')->first();

        $districts = [
            // 北京市各区
            ['city_id' => $beijing->id, 'name' => '东城区', 'code' => '110101', 'sort_order' => 1],
            ['city_id' => $beijing->id, 'name' => '西城区', 'code' => '110102', 'sort_order' => 2],
            ['city_id' => $beijing->id, 'name' => '朝阳区', 'code' => '110105', 'sort_order' => 3],
            ['city_id' => $beijing->id, 'name' => '丰台区', 'code' => '110106', 'sort_order' => 4],
            ['city_id' => $beijing->id, 'name' => '石景山区', 'code' => '110107', 'sort_order' => 5],
            ['city_id' => $beijing->id, 'name' => '海淀区', 'code' => '110108', 'sort_order' => 6],
            ['city_id' => $beijing->id, 'name' => '门头沟区', 'code' => '110109', 'sort_order' => 7],
            ['city_id' => $beijing->id, 'name' => '房山区', 'code' => '110111', 'sort_order' => 8],
            ['city_id' => $beijing->id, 'name' => '通州区', 'code' => '110112', 'sort_order' => 9],
            ['city_id' => $beijing->id, 'name' => '顺义区', 'code' => '110113', 'sort_order' => 10],
            ['city_id' => $beijing->id, 'name' => '昌平区', 'code' => '110114', 'sort_order' => 11],
            ['city_id' => $beijing->id, 'name' => '大兴区', 'code' => '110115', 'sort_order' => 12],
            ['city_id' => $beijing->id, 'name' => '怀柔区', 'code' => '110116', 'sort_order' => 13],
            ['city_id' => $beijing->id, 'name' => '平谷区', 'code' => '110117', 'sort_order' => 14],
            ['city_id' => $beijing->id, 'name' => '密云区', 'code' => '110118', 'sort_order' => 15],
            ['city_id' => $beijing->id, 'name' => '延庆区', 'code' => '110119', 'sort_order' => 16],

            // 天津市各区
            ['city_id' => $tianjin->id, 'name' => '和平区', 'code' => '120101', 'sort_order' => 1],
            ['city_id' => $tianjin->id, 'name' => '河东区', 'code' => '120102', 'sort_order' => 2],
            ['city_id' => $tianjin->id, 'name' => '河西区', 'code' => '120103', 'sort_order' => 3],
            ['city_id' => $tianjin->id, 'name' => '南开区', 'code' => '120104', 'sort_order' => 4],
            ['city_id' => $tianjin->id, 'name' => '河北区', 'code' => '120105', 'sort_order' => 5],
            ['city_id' => $tianjin->id, 'name' => '红桥区', 'code' => '120106', 'sort_order' => 6],
            ['city_id' => $tianjin->id, 'name' => '东丽区', 'code' => '120110', 'sort_order' => 7],
            ['city_id' => $tianjin->id, 'name' => '西青区', 'code' => '120111', 'sort_order' => 8],
            ['city_id' => $tianjin->id, 'name' => '津南区', 'code' => '120112', 'sort_order' => 9],
            ['city_id' => $tianjin->id, 'name' => '北辰区', 'code' => '120113', 'sort_order' => 10],
            ['city_id' => $tianjin->id, 'name' => '武清区', 'code' => '120114', 'sort_order' => 11],
            ['city_id' => $tianjin->id, 'name' => '宝坻区', 'code' => '120115', 'sort_order' => 12],
            ['city_id' => $tianjin->id, 'name' => '滨海新区', 'code' => '120116', 'sort_order' => 13],
            ['city_id' => $tianjin->id, 'name' => '宁河区', 'code' => '120117', 'sort_order' => 14],
            ['city_id' => $tianjin->id, 'name' => '静海区', 'code' => '120118', 'sort_order' => 15],
            ['city_id' => $tianjin->id, 'name' => '蓟州区', 'code' => '120119', 'sort_order' => 16],

            // 哈尔滨市各区县
            ['city_id' => $haerbin->id, 'name' => '道里区', 'code' => '230102', 'sort_order' => 1],
            ['city_id' => $haerbin->id, 'name' => '南岗区', 'code' => '230103', 'sort_order' => 2],
            ['city_id' => $haerbin->id, 'name' => '道外区', 'code' => '230104', 'sort_order' => 3],
            ['city_id' => $haerbin->id, 'name' => '平房区', 'code' => '230108', 'sort_order' => 4],
            ['city_id' => $haerbin->id, 'name' => '松北区', 'code' => '230109', 'sort_order' => 5],
            ['city_id' => $haerbin->id, 'name' => '香坊区', 'code' => '230110', 'sort_order' => 6],
            ['city_id' => $haerbin->id, 'name' => '呼兰区', 'code' => '230111', 'sort_order' => 7],
            ['city_id' => $haerbin->id, 'name' => '阿城区', 'code' => '230112', 'sort_order' => 8],
            ['city_id' => $haerbin->id, 'name' => '双城区', 'code' => '230113', 'sort_order' => 9],
            ['city_id' => $haerbin->id, 'name' => '依兰县', 'code' => '230123', 'sort_order' => 10],
            ['city_id' => $haerbin->id, 'name' => '方正县', 'code' => '230124', 'sort_order' => 11],
            ['city_id' => $haerbin->id, 'name' => '宾县', 'code' => '230125', 'sort_order' => 12],
            ['city_id' => $haerbin->id, 'name' => '巴彦县', 'code' => '230126', 'sort_order' => 13],
            ['city_id' => $haerbin->id, 'name' => '木兰县', 'code' => '230127', 'sort_order' => 14],
            ['city_id' => $haerbin->id, 'name' => '通河县', 'code' => '230128', 'sort_order' => 15],
            ['city_id' => $haerbin->id, 'name' => '延寿县', 'code' => '230129', 'sort_order' => 16],
            ['city_id' => $haerbin->id, 'name' => '尚志市', 'code' => '230183', 'sort_order' => 17],
            ['city_id' => $haerbin->id, 'name' => '五常市', 'code' => '230184', 'sort_order' => 18],

            // 齐齐哈尔市各区县
            ['city_id' => $qiqihaer->id, 'name' => '龙沙区', 'code' => '230202', 'sort_order' => 1],
            ['city_id' => $qiqihaer->id, 'name' => '建华区', 'code' => '230203', 'sort_order' => 2],
            ['city_id' => $qiqihaer->id, 'name' => '铁锋区', 'code' => '230204', 'sort_order' => 3],
            ['city_id' => $qiqihaer->id, 'name' => '昂昂溪区', 'code' => '230205', 'sort_order' => 4],
            ['city_id' => $qiqihaer->id, 'name' => '富拉尔基区', 'code' => '230206', 'sort_order' => 5],
            ['city_id' => $qiqihaer->id, 'name' => '碾子山区', 'code' => '230207', 'sort_order' => 6],
            ['city_id' => $qiqihaer->id, 'name' => '梅里斯达斡尔族区', 'code' => '230208', 'sort_order' => 7],
            ['city_id' => $qiqihaer->id, 'name' => '龙江县', 'code' => '230221', 'sort_order' => 8],
            ['city_id' => $qiqihaer->id, 'name' => '依安县', 'code' => '230223', 'sort_order' => 9],
            ['city_id' => $qiqihaer->id, 'name' => '泰来县', 'code' => '230224', 'sort_order' => 10],
            ['city_id' => $qiqihaer->id, 'name' => '甘南县', 'code' => '230225', 'sort_order' => 11],
            ['city_id' => $qiqihaer->id, 'name' => '富裕县', 'code' => '230227', 'sort_order' => 12],
            ['city_id' => $qiqihaer->id, 'name' => '克山县', 'code' => '230229', 'sort_order' => 13],
            ['city_id' => $qiqihaer->id, 'name' => '克东县', 'code' => '230230', 'sort_order' => 14],
            ['city_id' => $qiqihaer->id, 'name' => '拜泉县', 'code' => '230231', 'sort_order' => 15],
            ['city_id' => $qiqihaer->id, 'name' => '讷河市', 'code' => '230281', 'sort_order' => 16],

            // 大庆市各区县
            ['city_id' => $daqing->id, 'name' => '萨尔图区', 'code' => '230602', 'sort_order' => 1],
            ['city_id' => $daqing->id, 'name' => '龙凤区', 'code' => '230603', 'sort_order' => 2],
            ['city_id' => $daqing->id, 'name' => '让胡路区', 'code' => '230604', 'sort_order' => 3],
            ['city_id' => $daqing->id, 'name' => '红岗区', 'code' => '230605', 'sort_order' => 4],
            ['city_id' => $daqing->id, 'name' => '大同区', 'code' => '230606', 'sort_order' => 5],
            ['city_id' => $daqing->id, 'name' => '肇州县', 'code' => '230621', 'sort_order' => 6],
            ['city_id' => $daqing->id, 'name' => '肇源县', 'code' => '230622', 'sort_order' => 7],
            ['city_id' => $daqing->id, 'name' => '林甸县', 'code' => '230623', 'sort_order' => 8],
            ['city_id' => $daqing->id, 'name' => '杜尔伯特蒙古族自治县', 'code' => '230624', 'sort_order' => 9],

            // 上海市各区
            ['city_id' => $shanghai->id, 'name' => '黄浦区', 'code' => '310101', 'sort_order' => 1],
            ['city_id' => $shanghai->id, 'name' => '徐汇区', 'code' => '310104', 'sort_order' => 2],
            ['city_id' => $shanghai->id, 'name' => '长宁区', 'code' => '310105', 'sort_order' => 3],
            ['city_id' => $shanghai->id, 'name' => '静安区', 'code' => '310106', 'sort_order' => 4],
            ['city_id' => $shanghai->id, 'name' => '普陀区', 'code' => '310107', 'sort_order' => 5],
            ['city_id' => $shanghai->id, 'name' => '虹口区', 'code' => '310109', 'sort_order' => 6],
            ['city_id' => $shanghai->id, 'name' => '杨浦区', 'code' => '310110', 'sort_order' => 7],
            ['city_id' => $shanghai->id, 'name' => '闵行区', 'code' => '310112', 'sort_order' => 8],
            ['city_id' => $shanghai->id, 'name' => '宝山区', 'code' => '310113', 'sort_order' => 9],
            ['city_id' => $shanghai->id, 'name' => '嘉定区', 'code' => '310114', 'sort_order' => 10],
            ['city_id' => $shanghai->id, 'name' => '浦东新区', 'code' => '310115', 'sort_order' => 11],
            ['city_id' => $shanghai->id, 'name' => '金山区', 'code' => '310116', 'sort_order' => 12],
            ['city_id' => $shanghai->id, 'name' => '松江区', 'code' => '310117', 'sort_order' => 13],
            ['city_id' => $shanghai->id, 'name' => '青浦区', 'code' => '310118', 'sort_order' => 14],
            ['city_id' => $shanghai->id, 'name' => '奉贤区', 'code' => '310120', 'sort_order' => 15],
            ['city_id' => $shanghai->id, 'name' => '崇明区', 'code' => '310151', 'sort_order' => 16],

            // 广州市各区
            ['city_id' => $guangzhou->id, 'name' => '荔湾区', 'code' => '440103', 'sort_order' => 1],
            ['city_id' => $guangzhou->id, 'name' => '越秀区', 'code' => '440104', 'sort_order' => 2],
            ['city_id' => $guangzhou->id, 'name' => '海珠区', 'code' => '440105', 'sort_order' => 3],
            ['city_id' => $guangzhou->id, 'name' => '天河区', 'code' => '440106', 'sort_order' => 4],
            ['city_id' => $guangzhou->id, 'name' => '白云区', 'code' => '440111', 'sort_order' => 5],
            ['city_id' => $guangzhou->id, 'name' => '黄埔区', 'code' => '440112', 'sort_order' => 6],
            ['city_id' => $guangzhou->id, 'name' => '番禺区', 'code' => '440113', 'sort_order' => 7],
            ['city_id' => $guangzhou->id, 'name' => '花都区', 'code' => '440114', 'sort_order' => 8],
            ['city_id' => $guangzhou->id, 'name' => '南沙区', 'code' => '440115', 'sort_order' => 9],
            ['city_id' => $guangzhou->id, 'name' => '从化区', 'code' => '440117', 'sort_order' => 10],
            ['city_id' => $guangzhou->id, 'name' => '增城区', 'code' => '440118', 'sort_order' => 11],

            // 深圳市各区
            ['city_id' => $shenzhen->id, 'name' => '罗湖区', 'code' => '440303', 'sort_order' => 1],
            ['city_id' => $shenzhen->id, 'name' => '福田区', 'code' => '440304', 'sort_order' => 2],
            ['city_id' => $shenzhen->id, 'name' => '南山区', 'code' => '440305', 'sort_order' => 3],
            ['city_id' => $shenzhen->id, 'name' => '宝安区', 'code' => '440306', 'sort_order' => 4],
            ['city_id' => $shenzhen->id, 'name' => '龙岗区', 'code' => '440307', 'sort_order' => 5],
            ['city_id' => $shenzhen->id, 'name' => '盐田区', 'code' => '440308', 'sort_order' => 6],
            ['city_id' => $shenzhen->id, 'name' => '龙华区', 'code' => '440309', 'sort_order' => 7],
            ['city_id' => $shenzhen->id, 'name' => '坪山区', 'code' => '440310', 'sort_order' => 8],
            ['city_id' => $shenzhen->id, 'name' => '光明区', 'code' => '440311', 'sort_order' => 9],
        ];

        foreach ($districts as $district) {
            District::create($district);
        }
    }
}